using System;
using System.Data;
using System.Collections.Generic;
namespace eTMS.DAO
{
    /********************************BEGIN DangKyHocPhanDAO****************************************/
    ///<summary>
    /// <para>Author: Auto generated class by CSharp Code Generator v2.0</para>
    /// <para>Date:02/10/2010 35:09:36</para>
    /// <para>Class Name: DangKyHocPhanDAO</para>
    /// <para>Description: Class access to table DangKyHocPhan in database. Class for coder code here</para>
    ///</summary>


    public partial class DangKyHocPhanDAO
    {
        public DataSet SelectAllDSMonHocDaDangKy(int SinhVien_ID, int NamHoc_ID, int HocKy_ID, int ChuongTrinhDaoTao_ID)
        {
            IDbCommand cmd = this.CreateCommand();
            cmd.CommandText = @"SELECT        MonHoc.MaMonHoc, MonHoc.TenMonHoc, DangKyHocPhan.DangKyHocPhan_ID, DangKyHocPhan.SinhVien_ID, DangKyHocPhan.HocKy_ID, 
                                            DangKyHocPhan.NamHoc_ID, DangKyHocPhan.MonHoc_ID, ChiTietChuongTrinh.BatBuocQuaTrongHocKy, ChiTietChuongTrinh.BatBuocQuaTrongNam, 
                                            MonHoc.SoHocPhan, MonHoc.SoHocPhanHocPhi
                              FROM          MonHoc INNER JOIN
                                            DangKyHocPhan ON MonHoc.MonHoc_ID = DangKyHocPhan.MonHoc_ID INNER JOIN
                                            ChiTietChuongTrinh ON MonHoc.MonHoc_ID = ChiTietChuongTrinh.MonHoc_ID ";
            cmd.CommandText += " WHERE DangKyHocPhan.NamHoc_ID=" + NamHoc_ID.ToString();
            cmd.CommandText += " AND DangKyHocPhan.HocKy_ID=" + HocKy_ID.ToString();
            cmd.CommandText += " AND DangKyHocPhan.SinhVien_ID=" + SinhVien_ID.ToString();
            cmd.CommandText += " AND ChiTietChuongTrinh.ChuongTrinhDaoTao_ID=" + ChuongTrinhDaoTao_ID.ToString();
            return this.SelectDS(cmd);
        }
     
        public bool SaveList(List<DangKyHocPhanEntity> lsDangKy)
        {
            if (lsDangKy.Count == 0) return true;
            IDbCommand cmd = this.CreateCommand();
            cmd.CommandText += "INSERT INTO DangKyHocPhan(SinhVien_ID, HocKy_ID, NamHoc_ID, MonHoc_ID,NgayDangKy)";
            List<string> ls = new List<string>();
            foreach (DangKyHocPhanEntity o in lsDangKy)
            {
                ls.Add("SELECT " + o.SinhVien_ID.ToString() + "," + o.HocKy_ID + "," + o.NamHoc_ID.ToString() + "," + o.MonHoc_ID + ",@NgayDangKy");
            }
            cmd.CommandText += string.Join(" UNION ", ls.ToArray());
            this.CreateCommandParameter(cmd, "@NgayDangKy", lsDangKy[0].NgayDangKy);
            return this.ExcuteNoneQuery(cmd);
        }
        public DataSet SelectAllDSDangKyHocPhan_ID(int NamHoc_ID, int HocKy_ID, int MonHoc_ID, List<int> LsSinhVien_ID)
        {
            IDbCommand cmd = this.CreateCommand();
            cmd.CommandText += "SELECT DangKyHocPhan_ID,SinhVien_ID FROM DangKyHocPhan WHERE SinhVien_ID IN(" + string.Join(",", LsSinhVien_ID.ConvertAll<string>(Convert.ToString).ToArray()) + ") ";
            cmd.CommandText += "AND NamHoc_ID=" + NamHoc_ID.ToString() + " AND HocKy_ID=" + HocKy_ID.ToString() + " AND MonHoc_ID=" + MonHoc_ID.ToString();
            return this.SelectDS(cmd);
        }
    }
    /*****************************************************************************************************/
    /**********************************END DangKyHocPhanDAO*****************************************/
    /*****************************************************************************************************/
}

